package com.buercorp.wangyu.core1.ch9;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class Iteraor {
    public static void main(String[] args) {
//        List<String> myList = new ArrayList<>();
//        myList.add("Apple");
//        myList.add("Banana");
//        myList.add("Orange");
//
//        Iterator<String> iterator = myList.iterator();
//        myList.forEach(element -> System.out.println(element));


//        iterator.forEachRemaining(element -> {
//            System.out.println(element);
//
//
//
//        });
//
//        iterator.forEachRemaining(element -> System.out.println(element));


        List<String> myList = Arrays.asList("Apple", "Banana", "Orange", "Orange2", "Orange3");
        Iterator<String> iterator = myList.iterator();
        int index = 0;
        while (iterator.hasNext()) {
            String element = iterator.next();
            System.out.println("index: " + index + ", element: " + element);
            index++;

            if (index == 3) {
                break;
            }
        }

        System.out.println("forEachRemaining print.");

        iterator.forEachRemaining(element -> System.out.println(element));
    }
}
